import obj2arg from "graphql-obj2arg";
import {Modal} from 'antd';
export const createCmd = (obj = {}) => {
  return `
mutation{
createCmd(cmd:{
  code:"${obj.code}"
  description:"${obj.description}"
}){
  list{
    code,
    description
  }
}
}
  `;
};
export const cmdList =({page, pageSize})=>{
  return `
  query{
    cmd(page: ${page}, pageSize: ${pageSize}){
      list{
        id,
        code,
        description
      }
      page,
      pageSize,
      totalCount
    }
  }
    `
};
export const deleteCmd = (id) => {
  return `
  mutation{
    deleteCmd(id:"${id}"){
      list{
        id,
        code,
      }
    }
  }
    `
}
export const updateCmd = (id, args) => {
  return `mutation{
    updateCmd(id:"${id}", cmd:${obj2arg(args)}){
      id,
      code
    }
  }`
}
//  参数设置
export const createParams = ({ code, description, params }) => {
  try{
    params = JSON.parse(params)

  } catch (err){
    Modal.error({
      title: '啊席八',
      content: '参数格式不合法啊',
    });
    return
  }
  return `mutation{
    createDefparam(param: {code:"${code}", description: "${description}", params: ${obj2arg(params)}}){
      code,
      description,
      params
    }
  }`
}
export const updateParams = (id, args) => {
  try{
    args.params = JSON.parse(args.params)
  } catch (err){
    Modal.error({
      title: '啊席八',
      content: '参数格式不合法啊',
    });
    return
  }
  return `mutation{
    updateDefparam(_id:"${id}",params:${obj2arg(args)}){
      code,
      description
    }
  }`
}
export const getParamsList =({page = 1, pageSize=10, query={}})=>{
  return `
  query{
    defaultParams(page: ${page}, pageSize: ${pageSize}, params: ${obj2arg(query)}){
      page,
      pageSize,
      list{
        _id,
        code,
        description,
        params
      },
      totalCount
    }
  }
    `
};
export const deleteParams = (id) => {
  return `
  mutation{
    deleteParams(_id:"${id}"){
      list{
        _id,
        code,
      }
    }
  }
    `
}

